home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Toolkit / Songbird 0.1 / Songbird_0_1_0.exe / chrome / content / rmp_demo.js < prev    next >
Text File  |  2006-02-09  |  11KB  |  373 lines

  1. /*
  2. //
  3. // BEGIN SONGBIRD GPL
  4. // 
  5. // This file is part of the Songbird web player.
  6. //
  7. // Copyright⌐ 2006 Pioneers of the Inevitable LLC
  8. // http://songbirdnest.com
  9. // 
  10. // This file may be licensed under the terms of of the
  11. // GNU General Public License Version 2 (the ôGPLö).
  12. // 
  13. // Software distributed under the License is distributed 
  14. // on an ôAS ISö basis, WITHOUT WARRANTY OF ANY KIND, either 
  15. // express or implied. See the GPL for the specific language 
  16. // governing rights and limitations.
  17. //
  18. // You should have received a copy of the GPL along with this 
  19. // program. If not, go to http://www.gnu.org/licenses/gpl.html
  20. // or write to the Free Software Foundation, Inc., 
  21. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. // 
  23. // END SONGBIRD GPL
  24. //
  25.  */
  26.  
  27. //
  28. // XUL Event Methods
  29. //
  30.  
  31. // The background image allows us to move the window around the screen
  32. function onBkgDown( theEvent ) 
  33. {
  34.   var windowDragger = Components.classes["@songbird.org/Songbird/WindowDragger;1"].getService(Components.interfaces.sbIWindowDragger);
  35.   windowDragger.BeginWindowDrag(0); // automatically ends
  36. }
  37. function onBkgUp( ) 
  38. {
  39. }
  40. // old version, just in case
  41. /*var trackerBkg = false;
  42. var offsetScrX = 0;
  43. var offsetScrY = 0;
  44. function onBkgDown( theEvent ) 
  45. {
  46.   trackerBkg = true;
  47.   offsetScrX = document.defaultView.screenX - theEvent.screenX;
  48.   offsetScrY = document.defaultView.screenY - theEvent.screenY;
  49.   document.addEventListener( "mousemove", onBkgMove, true );
  50. }
  51. function onBkgMove( theEvent ) 
  52. {
  53.   if ( trackerBkg )
  54.   {
  55. //    window.moveTo( offsetScrX + theEvent.screenX, offsetScrY + theEvent.screenY );
  56.     document.defaultView.moveTo( offsetScrX + theEvent.screenX, offsetScrY + theEvent.screenY );
  57.   }
  58. }
  59. function onBkgUp( ) 
  60. {
  61.   if ( trackerBkg )
  62.   {
  63.     trackerBkg = false;
  64.     document.removeEventListener( "mousemove", onBkgMove, true );
  65.   }
  66. }*/
  67.  
  68. // Help
  69. function onHelp()
  70. {
  71.   alert( "Aieeeeee, ayudame!" );
  72. }
  73.  
  74. // Minimize
  75. function onMinimize()
  76. {
  77.   document.defaultView.minimize();
  78. }
  79.  
  80. // Maximize
  81. var maximized = false;
  82. function onMaximize()
  83. {
  84.   if ( maximized )
  85.   {
  86.     document.defaultView.restore();
  87.     maximized = false;
  88.   }
  89.   else
  90.   {
  91.     document.defaultView.maximize();
  92.     maximized = true;
  93.   }
  94. }
  95.  
  96. // Exit
  97. function onExit()
  98. {
  99.   try
  100.   {
  101.     var root = "window." + document.documentElement.id;
  102.     SBDataSetValue( root + ".x", document.documentElement.boxObject.screenX );
  103.     SBDataSetValue( root + ".y", document.documentElement.boxObject.screenY );
  104.     SBDataSetValue( root + ".w", document.documentElement.boxObject.width );
  105.     SBDataSetValue( root + ".h", document.documentElement.boxObject.height );
  106.   }
  107.   catch ( err )
  108.   {
  109.     // If you don't have data functions, just close.
  110.   }
  111.   document.defaultView.close();
  112. }
  113.  
  114. function onWindowLoadSize()
  115. {
  116.   var root = "window." + document.documentElement.id;
  117.   if ( SBDataGetIntValue( root + ".w" ) && SBDataGetIntValue( root + ".h" ) )
  118.   {
  119.     // https://bugzilla.mozilla.org/show_bug.cgi?id=322788
  120.     // YAY YAY YAY the windowregion hack actualy fixes this :D
  121.     window.resizeTo( SBDataGetIntValue( root + ".w" ), SBDataGetIntValue( root + ".h" ) );
  122.     // for some reason, the resulting size isn't what we're asking (window currently has a border?) so determine what the difference is and add it to the resize
  123.     var diffw = SBDataGetIntValue( root + ".w" ) - document.documentElement.boxObject.width;
  124.     var diffh = SBDataGetIntValue( root + ".h" ) - document.documentElement.boxObject.height;
  125.     window.resizeTo( SBDataGetIntValue( root + ".w" ) + diffw, SBDataGetIntValue( root + ".h" ) + diffh);
  126.   }
  127.   window.moveTo( SBDataGetIntValue( root + ".x" ), SBDataGetIntValue( root + ".y" ) );
  128.   // do the (more or less) same adjustment for x,y as we did for w,h
  129.   var diffx = SBDataGetIntValue( root + ".x" ) - document.documentElement.boxObject.screenX;
  130.   var diffy = SBDataGetIntValue( root + ".y" ) - document.documentElement.boxObject.screenY;
  131.   window.moveTo( SBDataGetIntValue( root + ".x" ) - diffx, SBDataGetIntValue( root + ".y" ) - diffy );
  132. }
  133.  
  134. function ConvertUrlToDisplayName( url )
  135. {
  136.   // Set the title display  
  137.   var the_value = "";
  138.   if ( url.lastIndexOf('/') != -1 )
  139.   {
  140.     the_value = url.substring( url.lastIndexOf('/') + 1, url.length );
  141.   }
  142.   else if ( url.lastIndexOf('\\') != -1 )
  143.   {
  144.     the_value = url.substring( url.lastIndexOf('\\') + 1, url.length );
  145.   }
  146.   else
  147.   {
  148.     the_value = url;
  149.   }
  150.   // Convert any %XX to space
  151.   var percent = the_value.indexOf('%');
  152.   if ( percent != -1 )
  153.   {
  154.     var remainder = the_value;
  155.     the_value = "";
  156.     while ( percent != -1 )
  157.     {
  158.       the_value += remainder.substring( 0, percent );
  159.       remainder = remainder.substring( percent + 3, url.length );
  160.       percent = remainder.indexOf('%');
  161.       the_value += " ";
  162.       if ( percent == -1 )
  163.       {
  164.         the_value += remainder;
  165.       }
  166.     }
  167.   }
  168.   if ( ! the_value.length )
  169.   {
  170.     the_value = url;
  171.   }
  172.   return the_value;
  173. }
  174.  
  175. document.restartOnPlaybackEnd = false;
  176. function restartApp()
  177. {
  178.   thePlayerRepeater.doStop();
  179.   onExit();
  180.  
  181.   var as = Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(Components.interfaces.nsIAppStartup);
  182.   if (as)
  183.   {
  184.     const V_RESTART = 16;
  185.     const V_ATTEMPT = 2;
  186.     as.quit(V_RESTART);
  187.     as.quit(V_ATTEMPT);
  188.   }
  189. }
  190.  
  191. function quitApp()
  192. {
  193.   thePlayerRepeater.doStop();
  194.   onExit();
  195.  
  196.   var as = Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(Components.interfaces.nsIAppStartup);
  197.   if (as)
  198.   {
  199.     const V_ATTEMPT = 2;
  200.     as.quit(V_ATTEMPT);
  201.   }
  202. }
  203.  
  204. function SBAppDeinitialize()
  205. {
  206.   // Unattach the player repeater.
  207.   thePlayerRepeater.unbind();
  208. }
  209.  
  210. function SBAppInitialize()
  211. {
  212.   try
  213.   {
  214.     /*
  215. var docShell = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
  216. docShell = docShell.getInterface(Components.interfaces.nsIWebNavigation);
  217. //docShell = docShell.QueryInterface(Components.interfaces.nsIDocShellTreeItem); á 
  218. var baseWindow = docShell.treeOwner á áá áá áá áá 
  219. á     .QueryInterface(Components.interfaces.nsIInterfaceRequestor) á áá áá áá áá 
  220. á     .getInterface(Components.interfaces.nsIXULWindow) á áá áá áá áá 
  221. á     .QueryInterface(Components.interfaces.nsIBaseWindow);
  222.     */
  223.  
  224.     /*
  225.     */
  226.     var theWMPInstance = document.getElementById( "core_wm" );
  227.  
  228.     /*
  229.     */
  230.     var theQTInstance = document.getElementById( "core_qt" );
  231.     
  232.     /*
  233.     */
  234.     var theVLCInstance = document.getElementById( "core_vlc" );
  235.  
  236.     // Bind the core instances to the core objects (I really should make these use createElementNS, if we can get it to work)      
  237.     //theWMPCore.bindInstance( theWMPInstance );
  238.     //theQTCore.bindInstance( theQTInstance );
  239.     theVLCCore.bindInstance( theVLCInstance );
  240.  
  241.     // Tell the repeater we will be playing only one specific type of media
  242.     //thePlayerRepeater.setPlaybackCore( theWMPCore );
  243.     //thePlayerRepeater.setPlaybackCore( theQTCore );
  244.     thePlayerRepeater.setPlaybackCore( theVLCCore );
  245.     
  246.     // Initialize Player loop default values
  247.     SBSetPlayerLoopDefaults();
  248.  
  249.     // Initialize Player controls default values
  250.     SBSetPlayerControlsDefaults();
  251.     //This creates the main library.
  252.     
  253.     try
  254.     {
  255.       aDBQuery = new sbIDatabaseQuery();
  256.       aDBQuery.SetAsyncQuery(true);
  257.       aDBQuery.SetDatabaseGUID("songbird");
  258.      
  259.       var aMediaLibrary = new sbIMediaLibrary();    
  260.       
  261.       if(aMediaLibrary)
  262.       {
  263.         aMediaLibrary = aMediaLibrary.QueryInterface(Components.interfaces.sbIMediaLibrary);
  264.         aMediaLibrary.SetQueryObject(aDBQuery);
  265.         aMediaLibrary.CreateDefaultLibrary();
  266.       }
  267.       
  268.       const PlaylistManager = new Components.Constructor("@songbird.org/Songbird/PlaylistManager;1", "sbIPlaylistManager");
  269.       var aPlaylistManager = new PlaylistManager();
  270.  
  271.       if(aPlaylistManager)
  272.       {
  273.         aPlaylistManager = aPlaylistManager.QueryInterface(Components.interfaces.sbIPlaylistManager);
  274.         aPlaylistManager.CreateDefaultPlaylistManager(aDBQuery);
  275.       }
  276.     }
  277.     catch(err)
  278.     {
  279.       alert(err);
  280.     }
  281.  
  282. /*
  283. */    
  284.     try
  285.     {
  286.       DPUpdaterInit(1);
  287.     }
  288.     catch(err)
  289.     {
  290.       alert("DPUpdaterInit(1) - " + err);
  291.     }
  292.     
  293.     try
  294.     {
  295.       WFInit();
  296.     }
  297.     catch(err)
  298.     {
  299.       alert("WFInit() - " + err);
  300.     }
  301.  
  302.     var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  303.  
  304.     try { prefs.getCharPref("extensions.getMoreExtensionsURL"); } 
  305.     catch (e) { prefs.setCharPref("extensions.getMoreExtensionsURL", "http://songbirdnest.com/extensions.rdf"); }
  306.     try { prefs.getCharPref("extensions.getMoreThemesURL"); } 
  307.     catch (e) { prefs.setCharPref("extensions.getMoreThemesURL", "http://songbirdnest.com/themes.rdf"); }
  308.  
  309.     prefs.setCharPref("xpinstall.dialog.confirm", "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul");
  310.     prefs.setCharPref("xpinstall.dialog.progress.chrome", "chrome://mozapps/content/extensions/extensions.xul?type=extensions");
  311.     prefs.setCharPref("xpinstall.dialog.progress.skin", "chrome://mozapps/content/extensions/extensions.xul?type=themes");
  312.     prefs.setCharPref("xpinstall.dialog.progress.type.chrome", "Extension:Manager-extensions");
  313.     prefs.setCharPref("xpinstall.dialog.progress.type.skin", "Extension:Manager-themes");
  314.     
  315.     // If we are a top level window, hide us.
  316.     if ( window.parent == window )
  317.     {
  318.       var hide = true;
  319.       if ( document.__dont_hide_rmpdemo_window )
  320.       {
  321.         hide = false;
  322.       }
  323.       if ( hide )
  324.       {
  325.         setTimeout(HideCoreWindow, 0);
  326.       }
  327.     }
  328.   }
  329.   catch( err )
  330.   {
  331.     alert( err );
  332.   }
  333. }
  334.  
  335. function HideCoreWindow() 
  336. {
  337.   var windowCloak = Components.classes["@songbird.org/Songbird/WindowCloak;1"].getService(Components.interfaces.sbIWindowCloak);
  338.   windowCloak.Cloak( document ); 
  339. }
  340.  
  341. function PushBackscanPause()
  342. {
  343.   try
  344.   {
  345.     SBDataSetValue('backscan.paused', SBDataGetIntValue('backscan.paused') + 1 );
  346.   }
  347.   catch ( err )
  348.   {
  349.     alert( "PushBackscanPause - " + err );
  350.   }
  351. }
  352.  
  353. function PopBackscanPause()
  354. {
  355.   try
  356.   {
  357.     var pause = SBDataGetIntValue('backscan.paused') - 1;
  358.     if ( pause < 0 ) pause = 0;
  359.     SBDataSetValue('backscan.paused', pause );
  360.   }
  361.   catch ( err )
  362.   {
  363.     alert( "PushBackscanPause - " + err );
  364.   }
  365. }
  366.  
  367. function SBOpenModalDialog( url, param1, param2, param3 )
  368. {
  369.   PushBackscanPause();
  370.   var retval = window.openDialog( url, param1, param2, param3 );
  371.   PopBackscanPause();
  372.   return retval;
  373. }